#include <gtest/gtest.h>
#include <iostream>
#include <vector>

using namespace ::std;

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target);
    int findN(vector<int>& nums, int start, int N);
};

vector<int> Solution::twoSum(vector<int>& nums, int target) {
    int indexA = 0, indexB;
    for(auto n : nums) {
        indexB = findN(nums, indexA + 1, target - n);
        if(-1 != indexB) return {indexA, indexB};
        indexA++;
    }
    return {};
}

int Solution::findN(vector<int>& nums, int start, int N) {
    for(int index = start; index < nums.size(); index++) {
        if(nums[index] == N) return index;
    }
    return -1;
}

class TwoSumCheck : public ::testing::Test {
public:
	class Solution solution;
	vector<int> vec = {10, 2, 3, 4, 5, 6};

	void SetUp() override {
     // Code here will be called immediately after the constructor (right
     // before each test).
  	}

	void TearDown() override {
     // Code here will be called immediately after each test (right
     // before the destructor).
  	}
};

TEST_F(TwoSumCheck, testFindN_withoutN) {
	ASSERT_TRUE(-1 == solution.findN(vec, 0, 8));
}

TEST_F(TwoSumCheck, testFindN_firstPosition) {
	ASSERT_TRUE(0 == solution.findN(vec, 0, 10));
}

TEST_F(TwoSumCheck, testFindN_lastPosition) {
	ASSERT_TRUE(5 == solution.findN(vec, 0, 6));
}

TEST_F(TwoSumCheck, testFindN_middlePosition) {
	ASSERT_TRUE(2 == solution.findN(vec, 0, 3));
}

TEST_F(TwoSumCheck, testTwoSum_1) {
	bool b = vector<int>{1, 2} == solution.twoSum(vec, 5);
	EXPECT_TRUE(b);
	vector<int> u{1, 2};
	vector<int> v = solution.twoSum(vec, 5);
	ASSERT_EQ(u, v);
	ASSERT_TRUE(u == v);
	// ASSERT_TRUE(vector<int>{1, 2} == solution.twoSum(vec, 5)); // error: macro "ASSERT_TRUE" passed 2 arguments, but takes just 1
	ASSERT_TRUE((vector<int>{1, 2}) == (solution.twoSum(vec, 5)));
	ASSERT_TRUE(vector<int>({1, 2}) == (solution.twoSum(vec, 5)));
	ASSERT_EQ((vector<int>{1, 2}), solution.twoSum(vec, 5));
	EXPECT_EQ((vector<int>{1, 2}), solution.twoSum(vec, 5));
}

TEST_F(TwoSumCheck, testTwoSum_2) {
	vector<int> nums({7,2,11,15});
	int target = 9;
	vector<int> out({0, 1});
	// vector<int> out(0, 1); // error
	// vector<int> o = solution.twoSum(nums, target);
	// cout << o[0] << "--"<< o[1] << endl;
	EXPECT_TRUE(out == solution.twoSum(nums, target));
}

TEST_F(TwoSumCheck, testTwoSum_3) {
	vector<int> nums({3,3,4});
	int target = 6;
	vector<int> out({0, 1});
	EXPECT_TRUE(out == solution.twoSum(nums, target));
}

int main() {
	::testing::InitGoogleTest();
	return RUN_ALL_TESTS();
}
